import 'dart:convert';

import 'package:easy_chat_app/commons/model/AppUserDetail.dart';
import 'package:easy_chat_app/commons/utils/RouteUtils.dart';
import 'package:easy_chat_app/commons/utils/UserHeadPortraitUtils.dart';
import 'package:easy_chat_app/commons/widget/UserHeadPortrait.dart';
import 'package:easy_chat_app/mobile/constants/MobileAppGlobalConstants.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';

class MobileUserQRCodePage extends StatefulWidget {
  const MobileUserQRCodePage({
    super.key,
  });

  @override
  State<StatefulWidget> createState() {
    return _MobileUserQRCodePage();
  }
}

class _MobileUserQRCodePage extends State<MobileUserQRCodePage> {
  AppUserDetail? appUserDetail;

  @override
  void initState() {
    super.initState();
    if (RouteUtils.currentRouteSettings().arguments != null) {
      appUserDetail =
          RouteUtils.currentRouteSettings().arguments as AppUserDetail;
    }
  }

  @override
  Widget build(BuildContext context) {
    if (appUserDetail == null) {
      return const SizedBox();
    }
    var userDetail = appUserDetail!;
    return Scaffold(
      appBar: AppBar(
        surfaceTintColor: MobileAppGlobalConstants.appBarSurfaceTintColor,
        backgroundColor: MobileAppGlobalConstants.appBarBackgroundColor,
      ),
      body: Container(
        color: Colors.white,
        width: double.infinity,
        padding: const EdgeInsets.only(left: 60, right: 60, top: 100),
        child: Container(
          child: Column(
            children: [
              Row(
                children: [
                  UserHeadPortrait.network(
                      size: 60,
                      userCode: userDetail.code!,
                      userHeadPortrait: userDetail.headPortrait!,
                      userHeadPortraitStoreType:
                          userDetail.headPortraitStoreType!),
                  const SizedBox(width: 15, height: 60),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        appUserDetail!.nickname ??= "",
                        style:
                            const TextStyle(color: Colors.black, fontSize: 18),
                      ),
                      Text(
                        appUserDetail!.nickname ??= "",
                        style: const TextStyle(
                            color: Color.fromRGBO(167, 167, 167, 1),
                            fontSize: 13),
                      ),
                    ],
                  )
                ],
              ),
              Container(
                padding: const EdgeInsets.only(top: 30),
                child: QrImageView(
                    padding: const EdgeInsets.all(0),
                    data: json.encode({"ECCode": appUserDetail!.code})),
              )
            ],
          ),
        ),
      ),
    );
  }
}
